<#-- 登录页 -->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    	<base href="${baseURL}">
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
		<title>登录 - ${title}</title>
		<meta name="keywords" content="${keywords}"/>
		<meta name="description" content="${description}"/>
		<link rel="shortcut icon" type="image/x-icon" href="${baseURL}${commonPath}images/favicon.ico" media="screen" />
		<link href="${commonPath}css/common.css" type="text/css" rel="stylesheet">
		<script src="${commonPath}js/cryptoJS/core.js" language="javascript" type="text/javascript"></script>
		<script src="${commonPath}js/cryptoJS/sha256.js" language="javascript" type="text/javascript"></script>
		<script language="javascript" src="${commonPath}js/tool.js" type="text/javascript"></script>
		<script language="javascript" src="${commonPath}js/ajax.js" type="text/javascript"></script>
		<script language="javascript" src="${commonPath}js/json2.js" type="text/javascript"></script>
		
    </head>
    <body>
    <#-- 引入页头 -->
    <@include action="${newPublic_2}"/>
   	<div class="skeleton backgroundModule">
		<div class="main wrap backgroundModule" >
	   		<div style="background: #fff; height: 1px;"></div>
	        <form id="loginForm" name="login" method="post" autocomplete="off" action="login?jumpUrl=${url_jumpUrl}" onkeydown="keydown(event);">
				<!-- 令牌标记 -->
				<input type="hidden" id="token" name="token" value="${token}">
	           	
	           	<div class="loginModule clearfix">
	           		<div class="head">
						<p class="title">用户登录</p>
					</div>
					<div class="box">
						<!-- 用户名 -->
						<div class="username">
			            	<span></span>
			            	<input id="userName" name="userName" type="text" autocomplete="off" maxLength="40" value="" tabindex="1" onfocus="inputBoxTip_click(this);" onblur="inputBoxTip_leave(this);" onkeyup="showClearUserNameBox(this);"/>
			            	<a class="clearUserName" id="clearUserName" href="javascript:void(0);" style="display:none;" onClick="javascript:clearUserName();" ></a>
			            	<label class="promptTag" id="userNameBoxTip" for="userName" style="display:block">用户名</label>
			            </div>
						<p class="tips">
			            	<span id="userName_error">${(error['userName'])!}</span>
			            </p>
			            <!-- 密码 -->
						<div class="password">
							<span></span>
							<input id="password" name="password" type="password" maxLength="20" autocomplete="off" tabindex="2" onfocus="inputBoxTip_click(this);" onblur="inputBoxTip_leave(this);"/>
							<label class="promptTag" id="passwordBoxTip" style="display: block;" for="password">密码</label>
						</div>
						<p class="tips">
							<span id="password_error" >${(error['password'])!}</span>
						</p>
						<!-- 验证码 -->
						<div class="captcha_div" id="captcha_div" <#if formCaptcha.showCaptcha?c == 'false'>style='display: none;'</#if>>
							<div class="captchaBox">
								<span></span>
								<input type="hidden" id="captchaKey" name="captchaKey" value="${formCaptcha.captchaKey}">
								<input id="captchaValue" name="captchaValue" type="text" maxLength="4" autocomplete="off" tabindex="3" onfocus="inputBoxTip_click(this);" onblur="inputBoxTip_leave(this);"/>
								<label class="promptTag" id="captchaValueBoxTip" style="display: block;" for="captchaValue">验证码</label>
							</div>
							<a class="captchaImage" href="javascript:void(0);" >
								<img id="captcha" src="captcha/${formCaptcha.captchaKey}.jpg" onClick="replaceCaptcha();" tabindex="4" />
							</a>
							<a  href="javascript:void(0);" onClick="replaceCaptcha();" tabindex="5">换一幅</a>
						</div>
						<p class="tips">
							<span id="captchaValue_error">${(error['captchaValue'])!}</span>
						</p>
						
						<span id="token_error" style="color: red;">${(error['token'])!}</span>
						<!-- 忘记密码及自动登录  -->
						<p class="otherInfo">
							<a href="findPassWord/step1" tabindex="8">找回密码？</a>
							
							<label>
								<input id="rememberMe" name="rememberMe" type="checkbox" value="true"/>
								<span>自动登录</span>
							</label>
						</p>
						
						
						<!-- 登录  -->
						<p class="loginButton">
							<a href="javascript:void(0);" onClick="javascript:ajaxSubmit()" tabindex="6">登&nbsp;录</a>
						</p>
					</div>
					
					
					<#-- 引入第三方登录模块 -->
					<@include action="${systemRelated_thirdPartyLogin_1}"/>
					
				</div>
				<div class="push"><!-- 将页脚固定在页面底部 --></div>
				
	        </form>
			</div>
		</div>
		<#-- 引入页脚 -->
		<@include action="${newPublic_3}"/>
		
		
        <script language="javascript" type="text/javascript">
		//回车键登录
		function keydown(event){
			//当按下回车键
            if(event.keyCode == 13){   
				ajaxSubmit();
            } 
		}
       
        
        
        
        //跳出框架
		if(window != top){
			top.location = window.location.href;//跳出框架
		}	
        
        
		//点击输入框提示
		function inputBoxTip_click(obj){
			document.getElementById(obj.id+"BoxTip").style.display="none";

		}
		//离开输入框提示
		function inputBoxTip_leave(obj){
			if(obj.value != ""){
				document.getElementById(obj.id+"BoxTip").style.display="none";
			}else{
				document.getElementById(obj.id+"BoxTip").style.display="";
			}
			verification(obj.id);
		}
		
		//显示清除用户名称框
		function showClearUserNameBox(obj){
			if(obj.value != ""){
				document.getElementById("clearUserName").style.display="";
			}else{
				document.getElementById("clearUserName").style.display="none";
			}
		}
		
		//清除用户名称
		function clearUserName(){
			document.getElementById("clearUserName").style.display="none";
			document.getElementById("userName").value="";
		}
		
		
		

		//确认提交
		function sureSubmit(){	
			if(allVerification() == false){
				alert("请填好资料再提交");
				return;
			}
		
			//密码需SHA256加密
			var password = document.getElementById("password").value;
			if(password != ""){
				document.getElementById("password").value = CryptoJS.SHA256(password);
			}
			
			document.getElementById("loginForm").submit();
		}
		
		//ajax提交
		function ajaxSubmit(){
			if(allVerification() == false){
				alert("请填好资料再提交");
				return;
			}
		
			var parameter = getParameter();
		
			post_request(function(value){
				if(value != ""){
					var returnValue = JSON.parse(value);//JSON转为对象
					
					var key_success = "";
					var key_error = null;
					var key_jumpUrl = null;
					var key_captchaKey = null;
					
					for(var key in returnValue){
						if(key == "success"){	
							key_success = returnValue[key];
						}else if(key == "error"){
							key_error = returnValue[key];
						}else if(key == "jumpUrl"){//跳转URL
							key_jumpUrl = returnValue[key];
						}else if(key == "captchaKey"){//显示验证码
							key_captchaKey = returnValue[key];
						}
					}
					
					//登录成功
					if(key_success == "true"){
						//跳转
						if(key_jumpUrl != null){
							window.location.href = (getBasePath()+key_jumpUrl);
						}
					}else{
						//显示错误
						if(key_error != null){
							for(var error in key_error){
								if(error != ""){
									if(error == "token"){//如果令牌错误
										//刷新当前页面
										window.location.reload();	
									}
									document.getElementById(error+"_error").innerHTML=key_error[error];	
								}
							}
						}
						if(key_captchaKey != null){
							document.getElementById("captcha_div").style.display="";
							//设置验证码Key
							document.getElementById("captchaKey").value = key_captchaKey;
							//设置验证码图片
							replaceCaptcha();
						}
					}
				}	
			},
				"login?&timestamp=" + new Date().getTime(), true,parameter);
	
		}
		
		
		//组装参数
		function getParameter(){
			var parameter = "";
	
			//url跳转参数
			var jumpUrl = getUrlParam("jumpUrl");
			if(jumpUrl != null){
				parameter += "&jumpUrl="+encodeURIComponent(jumpUrl);
			}
			//令牌标记
			var token = document.getElementById("token").value;
			parameter += "&token="+token;
			
			//验证码Key
			var captchaKey = document.getElementById("captchaKey");
			if(captchaKey != null){
				parameter += "&captchaKey="+encodeURIComponent(captchaKey.value);
			}
			//验证码值
			var captchaValue = document.getElementById("captchaValue");
			if(captchaValue != null){
				parameter += "&captchaValue="+encodeURIComponent(captchaValue.value);
			}
	
			//用户名
			var userName = document.getElementById("userName").value;
			parameter += "&userName="+encodeURIComponent(userName);
			//密码需SHA256加密
			var password = document.getElementById("password").value;
			if(password != ""){
				parameter += "&password="+ CryptoJS.SHA256(password);
			}
			//自动登录
			var rememberMe = document.getElementsByName("rememberMe");
			for(var i=0;i<rememberMe.length;i++){
				if(rememberMe[i].checked){
					parameter += "&rememberMe="+rememberMe[i].value;
				}
			} 
		
			//删除第一个&号,防止因为多了&号而出现警告: Parameters: Invalid chunk ignored.信息
			if(parameter.indexOf("&") == 0){
				parameter = parameter.substring(1,parameter.length);
			}
			return parameter;
		}
		
		
	
		//更换验证码
		function replaceCaptcha(){
			var captchaKey = document.getElementById("captchaKey").value;
			document.getElementById("captcha").src = "captcha/"+captchaKey+".jpg?" + Math.random(); 
		}
		
		
		//验证参数
		function verification(field){
			if(field == "userName"){//用户名
				
				var parameter = document.getElementById(field).value;
				if(parameter != ""){
				
					var parameter_trim = trim(parameter);
					if(parameter_trim != ""){
					
						if(getStringLeng(parameter_trim) < 3){
							document.getElementById(field+"_error").innerHTML = "用户名长度不能小于3位";
							return false;
						}
						if(getStringLeng(parameter_trim) >= 20){
							document.getElementById(field+"_error").innerHTML = "用户名长度不能大于20位";
							return false;
						}
						var pattern =  /^\w+$/;
		            	if(!pattern.test(parameter_trim)) { 
		                	document.getElementById(field+"_error").innerHTML = "用户名只能输入由数字、26个英文字母或者下划线组成";
							return false;
		            	}
					}else{
						document.getElementById(field+"_error").innerHTML = "用户名不能为空";
						return false;
					}
				}else{
				
					document.getElementById(field+"_error").innerHTML = "用户名不能为空";
					return false;
				}
			}
			if(field == "password"){//密码
				var parameter = document.getElementById(field).value;
				if(parameter != ""){
					var parameter_trim = trim(parameter);
					if(parameter_trim != ""){
						if(getStringLeng(parameter_trim) < 6){
							document.getElementById(field+"_error").innerHTML = "密码长度不能小于6位";
							return false;
						}
						if(getStringLeng(parameter_trim) > 20){
							document.getElementById(field+"_error").innerHTML = "密码长度不能大于20位";
							return false;
						}
					}else{
						document.getElementById(field+"_error").innerHTML = "密码不能为空";
						return false;
					}
				}else{
					document.getElementById(field+"_error").innerHTML = "密码不能为空";
					return false;
				}
			}
	
			if(field == "captchaValue"){//验证码
				if(document.getElementById("captcha_div").style.display !="none"){
					if( document.getElementById("captchaKey") != null){
						var captchaKey = document.getElementById("captchaKey").value;
						var parameter = document.getElementById(field).value;
						if(parameter != ""){
						
							var parameter_trim = trim(parameter);
							if(parameter_trim != ""){
								get_request(function(value){
					            	if(value == "false"){
						            	document.getElementById(field+"_error").innerHTML = "验证码错误";
					            	}
					            },
							 		"userVerification.htm?captchaKey="+captchaKey+"&captchaValue="+parameter_trim+"&timestamp=" + new Date().getTime(), true);
					            	
							}else{
								document.getElementById(field+"_error").innerHTML = "验证码不能为空";
								return false;
							}
						}else{
							document.getElementById(field+"_error").innerHTML = "验证码不能为空";
							return false;
						}
					}
				}
			}
			if(document.getElementById(field+"_error") != null){
				document.getElementById(field+"_error").innerHTML = "";
			}
			
			return true;
		}
		
		//验证全部参数
		function allVerification(){
			var isVerification = true;
			if(verification("userName") == false){
				isVerification = false;
			}
			if(verification("password") == false){
				isVerification = false;
			}
			return isVerification;
		}
	
		//禁止浏览器后退
		window.history.forward(1);
		</script>
    </body>
</html>